package com.springbook.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.springbook.Bike;
import com.springbook.forms.EditBikeForm;

public class SubmitAction extends BaseAction {

	public SubmitAction() {
		super();
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		EditBikeForm formbean=(EditBikeForm) form;
		Bike bike= new Bike();
		bike.setManufacturer(formbean.getManufacturer());
		bike.setModel(formbean.getModel());
		bike.setFrame(formbean.getFrame());
		bike.setSerialNo(formbean.getSerialNo());
		bike.setStatus(formbean.getStatus());
		bike.setWeight(formbean.getWeight());
		try {
			this.getStore().saveBike(bike);
			return mapping.findForward("success");
		} catch(Exception ex) {
			return mapping.findForward("failure");
		}
	}
	
	
}
